Page({

  /**
   * 页面的初始数据
   */
  data: {
    // editFirld: "",
    title: "",
    editValue: [],
    // originalValue: ""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.ensure(options)

  },

  ensure: function (options) {
    // console.log(options, 999)
    var editValue = JSON.parse(options.commoditySpecificationsDtos);
    if(!editValue||editValue.length<=0){
      editValue = [
        {
          commoditySpecificationsName: '', //商品规格名称
          commodityStock: null, // 库存数量
          inStoreFoodPrice: null, // 店内价格
          infiniteStock: null, // 0默认 1无限
        }
      ]
    }
    // var title = "商品规格"
    this.setData({
      // title: title,
      editValue: editValue,
      // originalValue: editValue
    })
    // wx.setNavigationBarTitle({
    //   title: title,
    // })
  },

  // bindKeyInput: function (e) {
  //   // var editValue = this.data.editFirld
  //   this.setData({
  //     editValue: e.detail.value
  //   });
  // },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    // let editValue = wx.getStorageSync("commoditySpecificationsDtos");
    // if(!editValue||editValue.length<=0){
    //   editValue = [
    //     {
    //       commoditySpecificationsName: '', //商品规格名称
    //       commodityStock: null, // 库存数量
    //       inStoreFoodPrice: null, // 店内价格
    //       infiniteStock: null, // 0默认 1无限
    //     }
    //   ]
    // }
    // this.setData({
    //   editValue: editValue||[]
    // });
  },
  addItem(){
    let obj = {
      commoditySpecificationsName: '', //商品规格名称
      commodityStock: null, // 库存数量
      inStoreFoodPrice: null, // 店内价格
      infiniteStock: null, // 0默认 1无限
    }
    let editValue = this.data.editValue
    editValue.push(obj)
    this.setData({
      editValue
    });
  },
  deleteModal(options){
    // console.log(options)
    let num = options.target.dataset.id
    let editValue1 = this.data.editValue
    let editValue = editValue1.filter((item,index)=>{ return index!=num })
    this.setData({
      editValue
    });
  },
  commoditySpecificationsNameChange(e){
    let value = e.detail.value
    let num = e.target.dataset.id
    let commoditySpecificationsName = 'editValue['+num+'].commoditySpecificationsName'
    this.setData({
      [commoditySpecificationsName]:value
    });
  },
  inStoreFoodPriceChange(e){
    let value = e.detail.value
    let num = e.target.dataset.id
    let inStoreFoodPrice = 'editValue['+num+'].inStoreFoodPrice'
    this.setData({
      [inStoreFoodPrice]:value
    });
  },
  infiniteStockChange(e){
    let value = e.detail.value
    let num = e.target.dataset.id
    let infiniteStock = 'editValue['+num+'].infiniteStock'
    this.setData({
      [infiniteStock]:value
    });
  },
  commodityStockChange(e){
    let value = e.detail.value
    let num = e.target.dataset.id
    let commodityStock = 'editValue['+num+'].commodityStock'
    this.setData({
      [commodityStock]:value
    });
  },
  comfirm(){
    wx.setStorageSync("commoditySpecificationsDtos", this.data.editValue)
    wx.navigateBack()
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    wx.setStorageSync("commoditySpecificationsDtos", this.data.editValue)
    // wx.setStorageSync("editFirld", this.data.editFirld)
    // wx.setStorageSync("editValue", this.data.editValue)
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})